import CryptoJS from 'crypto-js';

const AES_KEY = '31dfdedc-a893-45';
const AES_IV = '779b366c-8641-49';
const key = CryptoJS.enc.Utf8.parse(AES_KEY); // 密钥
const iv = CryptoJS.enc.Utf8.parse(AES_IV); // 密钥偏移量

// 加密方法
export function Encrypt(data) {
  const encrypted = CryptoJS.AES.encrypt(data, key, {
    iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.ZeroPadding,
  });
  return encrypted.toString();
}

// 解密方法
export function Decrypt(data) {
  const decrypt = CryptoJS.AES.decrypt(data, key, {
    iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.ZeroPadding,
  });
  const decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
  return decryptedStr.toString();
}
